package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseMalfeasance;
import com.ktgj.customer.service.ICaseMalfeasanceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 渎失职工单Controller
 * 
 * @author ruoyi
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/malfeasance")
public class CaseMalfeasanceController extends BaseController
{
    @Autowired
    private ICaseMalfeasanceService caseMalfeasanceService;

    /**
     * 查询渎失职工单列表
     */
    @PreAuthorize(hasPermi = "system:malfeasance:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseMalfeasance caseMalfeasance)
    {
        startPage();
        List<CaseMalfeasance> list = caseMalfeasanceService.selectCaseMalfeasanceList(caseMalfeasance);
        return getDataTable(list);
    }

    /**
     * 导出渎失职工单列表
     */
    @PreAuthorize(hasPermi = "system:malfeasance:export")
    @Log(title = "渎失职工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseMalfeasance caseMalfeasance) throws IOException
    {
        List<CaseMalfeasance> list = caseMalfeasanceService.selectCaseMalfeasanceList(caseMalfeasance);
        ExcelUtil<CaseMalfeasance> util = new ExcelUtil<CaseMalfeasance>(CaseMalfeasance.class);
        util.exportExcel(response, list, "渎失职工单数据");
    }

    /**
     * 获取渎失职工单详细信息
     */
//    @PreAuthorize(hasPermi = "system:malfeasance:query")
//    @GetMapping(value = "/{caseMalfeasanceId}")
    @PostMapping("/malfeasanceById")
    public AjaxResult getInfo(@RequestBody Map<String, Long> map)
    {
        Long malfeasanceId =  Long.valueOf(map.get("malfeasanceId"));
        return AjaxResult.success(caseMalfeasanceService.selectCaseMalfeasanceById(malfeasanceId));
    }

    /**
     * 新增渎失职工单
     */
    @PreAuthorize(hasPermi = "system:malfeasance:add")
    @Log(title = "渎失职工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseMalfeasance caseMalfeasance)
    {
        return toAjax(caseMalfeasanceService.insertCaseMalfeasance(caseMalfeasance));
    }

    /**
     * 修改渎失职工单
     */
//    @PreAuthorize(hasPermi = "system:malfeasance:edit")
//    @Log(title = "渎失职工单", businessType = BusinessType.UPDATE)
    @PostMapping("/malfeasanceEdit")
    public AjaxResult edit(@RequestBody CaseMalfeasance caseMalfeasance)
    {
        return toAjax(caseMalfeasanceService.updateCaseMalfeasance(caseMalfeasance));
    }

    /**
     * 删除渎失职工单
     */
    @PreAuthorize(hasPermi = "system:malfeasance:remove")
    @Log(title = "渎失职工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseMalfeasanceIds}")
    public AjaxResult remove(@PathVariable Long[] caseMalfeasanceIds)
    {
        return toAjax(caseMalfeasanceService.deleteCaseMalfeasanceByIds(caseMalfeasanceIds));
    }
}
